package Others._384_ShuffleanArray;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Solution {
    int[] nums;
    int[] origin;
    Random r = new Random();
    public Solution(int[] nums) {
        this.nums = nums;
        this.origin = nums.clone();
    }

    public List<Integer> getArrayCopy(int[] nums) {
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            res.add(nums[i]);
        }
        return res;
    }

    /** Resets the array to its original configuration and return it. */
    public int[] reset() {
        this.nums = origin;
        this.origin = origin.clone();
        return nums;
    }

    /** Returns a random shuffling of the array. */
    public int[] shuffle() {
        List<Integer> shuffle = getArrayCopy(nums);
        for (int i = 0; i < nums.length; i++) {
            int index = r.nextInt(shuffle.size());
            nums[i] = shuffle.get(index);
            shuffle.remove(index);
        }
        return nums;
    }
}
